package com.mazewei.dev.controller;

import com.mazewei.dev.service.AnnotationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 标注控制器
 * 提供REST API接口用于测试标注功能
 */
@RestController
@RequestMapping("/api/annotation")
public class AnnotationController {
    
    @Autowired
    private AnnotationService annotationService;
    
    /**
     * 标注教师姓名
     * @param teacherName 教师姓名
     * @return 标注结果
     */
    @GetMapping("/teacher")
    public Map<String, Object> annotateTeacher(@RequestParam String teacherName) {
        Map<String, Object> result = new HashMap<>();
        try {
            String annotated = annotationService.annotateTeacher(teacherName);
            result.put("success", true);
            result.put("original", teacherName);
            result.put("annotated", annotated);
            result.put("message", "教师姓名标注成功");
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "标注失败: " + e.getMessage());
        }
        return result;
    }
    
    /**
     * 标注班级名称
     * @param className 班级名称
     * @return 标注结果
     */
    @GetMapping("/class")
    public Map<String, Object> annotateClass(@RequestParam String className) {
        Map<String, Object> result = new HashMap<>();
        try {
            String annotated = annotationService.annotateClass(className);
            result.put("success", true);
            result.put("original", className);
            result.put("annotated", annotated);
            result.put("message", "班级名称标注成功");
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "标注失败: " + e.getMessage());
        }
        return result;
    }
    
    /**
     * 标注课程名称
     * @param courseName 课程名称
     * @return 标注结果
     */
    @GetMapping("/course")
    public Map<String, Object> annotateCourse(@RequestParam String courseName) {
        Map<String, Object> result = new HashMap<>();
        try {
            String annotated = annotationService.annotateCourse(courseName);
            result.put("success", true);
            result.put("original", courseName);
            result.put("annotated", annotated);
            result.put("message", "课程名称标注成功");
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "标注失败: " + e.getMessage());
        }
        return result;
    }
    
    /**
     * 批量标注示例
     * @param teacherName 教师名称
     * @param className 班级名称
     * @param courseName 课程名称
     * @return 标注结果
     */
    @GetMapping("/batch-example")
    public ResponseEntity<String> batchAnnotationExample(
            @RequestParam(defaultValue = "张三") String teacherName,
            @RequestParam(defaultValue = "一年级1班") String className,
            @RequestParam(defaultValue = "数学") String courseName) {
        
        String result = annotationService.batchAnnotate(teacherName, className, courseName);
        return ResponseEntity.ok(result);
    }
    
    /**
     * 获取系统信息
     * @return 系统信息
     */
    @GetMapping("/info")
    public Map<String, Object> getSystemInfo() {
        Map<String, Object> result = new HashMap<>();
        result.put("system", "Excel模板标注系统");
        result.put("version", "1.0.0");
        result.put("description", "用于对Excel模板中的班级、课程和教师名称进行标注");
        result.put("endpoints", new String[]{
            "GET /api/annotation/teacher?teacherName=丁清",
            "GET /api/annotation/class?className=一年1班",
            "GET /api/annotation/course?courseName=数学(一上)",
            "GET /api/annotation/batch-example",
            "GET /api/annotation/info"
        });
        return result;
    }
}